<%@ page import="com.alpha.bom.*,java.util.*"%>
<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
	pageEncoding="ISO-8859-1"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>Exam View Page</title>
</head>
<body>
	<c:set var="user" value="${sessionScope.user}"></c:set>
	<c:set var="exam" value="${requestScope.exam}"></c:set>
	<c:set var="view" value="${requestScope.view}"></c:set>
	
	<div id="header"><%@ include file="Header.jsp"%></div>
	<div id="content">
	<div id="navbar"><%@ include file="NavigationBar.jsp"%></div>
	
	<div id="main">
	
	<h1>Exam View Page</h1>
	Exam Name: ${exam.examName}
	<br>
	Exam ID: ${exam.examId}
	<br>
	Exam Status:
	<c:choose>
		<c:when test="${not exam.isLocked()}">
			Ongoing
			<c:set var="button" value="End Exam"></c:set>
			<c:set var="servlet" value="ExamActionServlet"></c:set>
		</c:when>
		<c:when test="${exam.isDone()}">
			Complete
			<c:set var="button" value="Generate Report"></c:set>
			<c:set var="servlet" value="ExamReportServlet"></c:set>
		</c:when>
		<c:otherwise>
			Locked
			<c:set var="button" value="Start Exam"></c:set>
			<c:set var="servlet" value="ExamActionServlet"></c:set>
		</c:otherwise>
	</c:choose>
	<form action="${servlet}" method="post">
		<input type="hidden" value="${exam.examId}" name="exam_id"/>
		<input type="submit" value="${button}" name="action" /></form>
	<form action="ExamViewServlet" method="get">
	<input type="hidden" value="${exam.examId}" name="exam_id"/>
	View: 
	<select name="view">
		<c:choose>
			<c:when test="${view eq 'Questions'}">
				<option value="Questions">Questions</option>
				<option value="Students">Examinees</option>
			</c:when>
			<c:otherwise>
				<option value="Students">Examinees</option>
				<option value="Questions">Questions</option>
			</c:otherwise>
		</c:choose>
	</select> <input type="submit" value="Go" /></form>
	<table border="1">
		<c:choose>
			<c:when test="${view eq 'Questions'}">
				<tr>
					<td>Type</td>
					<td>Question</td>
					<td>Choices</td>
					<td>Correct Answer</td>
				</tr>
				<c:forEach var="question" items="${exam.questions}">
					<tr>
						<td>${question.questionType}</td>
						<td>${question.question}</td>
						<c:choose>
						<c:when test="${question.questionType eq 'MultipleChoice'}">
							<td>${question.getChoices()}</td>
							<td>${question.getCorrectAnswer().getAnswer()}</td>
						</c:when>
						<c:when test="${question.questionType eq 'TrueOrFalse'}">
							<td>${question.getChoices()}</td>
							<td>${question.getCorrectAnswer().getAnswer()}</td>
						</c:when>
						</c:choose>
					</tr>
				</c:forEach>
			</c:when>
			<c:otherwise>
				<tr>
					<td>Examinee Id</td>
					<td>Examinee Name</td>
					<c:if test="${exam.isLocked()}">
						<td>Status</td>
					</c:if>
					<c:if test="${exam.isDone()}">
						<td>Details</td>
					</c:if>
				</tr>
				<c:forEach var="exam_response" items="${requestScope.responses}">
					<c:set var="student" value="${exam_response.student}"></c:set>
					<tr>
						<td>${student.userId}</td>
						<td>${student.lastName}, ${student.firstName}</td>
						<td><c:if test="${exam.isLocked()}">
							<c:choose>
							<c:when test="${exam_response.isComplete()}">
							Done
							</c:when>
							<c:otherwise>
							Not Done
							</c:otherwise>
							</c:choose>
						</c:if></td>
						<c:if test="${exam.isDone()}">
							<td><a href="StudentResponseServlet?exam_id=${exam.examId}&student_id=${student.userId}">View Report</a></td>
						</c:if>
					</tr>
				</c:forEach>
			</c:otherwise>
		</c:choose>
	</table>
	<c:if test="${view eq 'Students' and exam.isLocked() and !exam.isDone()}">
	<form action="AddStudentToExamServlet" method="post">
	<input type="submit" value="Add Examinees to Exam" />
	</form>
	</c:if>
	
	</div>
	</div>
</body>
</html>